package com.open.capacity.prints.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.prints.entity.BillGhyhzzsq;
import com.open.capacity.prints.service.BillGhyhzzsqService;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 工行银行转账申请表
 *
 * @author 
 * @email 
 * @date 2021-04-07 09:40:45
 */
@RestController
@RequestMapping("ghyhzzsqs")
@Api(tags = "工行银行转账申请表")
public class BillGhyhzzsqController {

    @Autowired
    private BillGhyhzzsqService billGhyhzzsqService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_ghyhzzsq:billghyhzzsq:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billGhyhzzsqService.pageAll(params);
        return pageResult;
    }

    /**
    * 查询单条记录
    */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_ghyhzzsq:billghyhzzsq:list')")
    public Result findById(String id) {
        return Result.succeed(billGhyhzzsqService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_ghyhzzsq:billghyhzzsq:save')")
    public Result save(@RequestBody @Valid BillGhyhzzsq billGhyhzzsq, String keyValue) {
    	 if(StringUtils.isEmpty(keyValue)) {
              billGhyhzzsqService.save(billGhyhzzsq);
	     }else {
          billGhyhzzsq.setId(keyValue);
          billGhyhzzsqService.update(billGhyhzzsq);
	     }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_ghyhzzsq:billghyhzzsq:delete')")
    public Result delete(@PathVariable String  id) {
            billGhyhzzsqService.delete(id);
        return Result.succeed("删除成功");
    }

}
